﻿using Batman.Jianbei.Forum.Core.ChatRoom;
using Batman.Jianbei.Forum.Core.Enums.Chatroom;
using System;

namespace Batman.Jianbei.Forum.DTOS.Chatroom
{
    /// <summary>
    /// 聊天室内的消息
    /// </summary>
    public class RoomMsgBaseDTO
    {
        /// <summary>
        /// 消息ID
        /// </summary>
        public string MsgId { get; set; }

        /// <summary>
        /// 消息类型
        /// </summary>
        public string RoomId { get; set; }

        /// <summary>
        /// 匿名ID
        /// </summary>
        public string MaskId { get; set; }

        /// <summary>
        /// 匿名昵称
        /// </summary>
        public string MaskName { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string Avatar { get; set; }

        /// <summary>
        /// 消息类型
        /// </summary>
        public RoomMsgType MsgType { get; set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        public string Msg { get; set; }

        public DateTime MsgTime { get; set; }

        private RoomMsgBaseDTO()
        {
            MsgId = Guid.NewGuid().ToString();
            MsgTime = DateTime.Now;
        }

        protected RoomMsgBaseDTO(string roomId, Mask mask, string message, RoomMsgType msgType) : this()
        {
            Msg = message;
            MaskId = mask.Id;
            MaskName = mask.Nickname;
            Avatar = mask.Avatar?.Url;
            RoomId = roomId;
            MsgType = msgType;
        }

        /// <summary>
        /// 获取SignaR发送消息所需要的方法名称
        /// </summary>
        /// <returns></returns>
        public virtual string GetMethod()
        {
            return $"{RoomId}_{MsgType}";
        }
    }
}
